package demo2;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-06-22
 * Time: 19:02
 */
public class Person {
    public String name;
    public int age;
    public char gender;

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }

    public Person(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

//    @Override
//    public boolean equals(Object obj) {
//        //判断是否引用的是同一个对象
//        if (this == obj) {
//            return true;
//        }
//        //判断是否是同一种数据类型
//        if (obj instanceof Person) {
//            //向下转型
//            Person per = (Person) obj;
//            return this.name.equals(per.name) && this.age == per.age &&
//                    this.gender == per.gender;
//        }
//        return false;
//    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && gender == person.gender && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, gender);
    }
}
